<?php
class Daftar extends CI_Controller {

	function __construct()
	{
		parent::__construct();	
		$this->load->helper('flexigrid');
		$this->load->library('flexigrid');
		$this->load->library('form_validation');		
		$this->load->model('helpdesk_model');		
		$this->load->model('kategori_model');		
	}
	
	function all()
	{
		//ver lib
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('NO',40,TRUE,'center',0);
		$colModel['ubah'] = array('EDIT',50,FALSE,'center',0);
		$colModel['detail'] = array('DETAIL',50,FALSE,'center',0);
		$colModel['KODE'] = array('KODE',60,TRUE,'center',2);
		$colModel['JENIS'] = array('JENIS',80,TRUE,'center',2);
		$colModel['SUB_JENIS'] = array('SUB JENIS',80,TRUE,'center',2);
		$colModel['ISI'] = array('ISI',180,TRUE,'center',1);
		$colModel['TGL_ENTRY'] = array('TGL ENTRY',60, TRUE,'center',2);
		$colModel['USER_ENTRY'] = array('USER ENTRY',200, TRUE,'center',2);
		$colModel['URAIAN'] = array('URAIAN',60, TRUE,'center',2);
		$colModel['USER_KERJA'] = array('USER KERJA',200, TRUE,'center',2);
		$colModel['TGL_SELESAI'] = array('TGL SELESAI',90, TRUE, 'center',2);
		$colModel['KET_SELESAI'] = array('KET SELESAI',90, TRUE, 'center',2);
		
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '355',
		'rp' => 15,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Menampilkan: {from} sampai {to} dari {total} data.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Keseluruhan Permasalahan'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */

		$buttons[] = array('Tambah Helpdesk','add','helpdesk_js');
		if ($this->session->userdata('jenis') == 'A'){
		$buttons[] = array('Assign Job','assign','helpdesk_js');
		$buttons[] = array('Complete Job','complete','helpdesk_js');
		$buttons[] = array('separator');
		$buttons[] = array('Pilih Semua','add','helpdesk_js');
		$buttons[] = array('Batal Memilih Semua','delete','helpdesk_js');
		//$buttons[] = array('separator');
        //$buttons[] = array('Cetak Data','print','helpdesk_js');
        //$buttons[] = array('separator');
    	}

		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("helpdesk/daftar/all_grid"),$colModel,'no','asc',$gridParams,$buttons);
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			function helpdesk_js(com,grid)
			{
				if (com=='Pilih Semua')
				{
					$('.bDiv tbody tr',grid).addClass('trSelected');
				}
				
				if (com=='Batal Memilih Semua')
				{
					$('.bDiv tbody tr',grid).removeClass('trSelected');
				}

				if (com=='Cetak Data')
                {
                    location.href='".base_url()."index.php/helpdesk/daftar/cetak/'; 
                }
				
				if (com=='Tambah Helpdesk')
				{
					location.href='".base_url()."index.php/helpdesk/daftar/input_helpdesk'; 
				}

				if (com=='Assign Job')
				{
					if($('.trSelected',grid).length>0){
					   	var items = $('.trSelected',grid);
						var itemlist ='';
						for(i=0;i<items.length;i++){
							itemlist+= items[i].id.substr(3)+',';
						}						

							$.ajax({
							   	type: 'POST',
							   	url: '".site_url('/helpdesk/daftar/assign_job/')."',
							   	data: 'items='+itemlist,
							   	success: function(data){
							   	newwindow=window.open('".site_url('/helpdesk/daftar/assign_job/')."',
							   	'Pilih User Kerja','height=150,width=350');
								newwindow.document.write(data);
							    if (window.focus) {newwindow.focus()}
							    return false;
								$('#flex1').flexReload();
								alert(data);
							   }
							});
					} else {
						return false;
					}				   	
				}
				
				if (com=='Complete Job')
				{
				   if($('.trSelected',grid).length>0){
					   if(confirm('Anda yakin telah menyelesaikan Job ini ?')){
							var items = $('.trSelected',grid);
							var itemlist ='';
							for(i=0;i<items.length;i++){
								itemlist+= items[i].id.substr(3)+',';
							}
							$.ajax({
							   type: 'POST',
							   url: '".site_url('/helpdesk/daftar/complete_job')."',
							   data: 'items='+itemlist,
							   success: function(data){
								$('#flex1').flexReload();
								alert(data);
							   }
							});
						}
					} else {
						return false;
					} 
				}          
			} 
			</script>
			";
		
		/* $data['notification'] = "";
		if($this->session->userdata('notification')!=''){
			$data['notification'] = "
				<script>
					$(document).ready(function() {
						$.growlUI('Pesan :', '".$this->session->userdata('notification')."'); 
					});
				</script>
			";
		}//end if */	
		
		$data['content'] = $this->load->view('grid',$data,true);
		$this->load->view('main',$data);
		//$this->load->view('grid',$data);
		//$this->load->view('flexigrid',$data);
	}
	
	function all_grid()
	{
	
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('KODE','JENIS','SUB_JENIS','ISI','TGL_ENTRY',
			'URAIAN','TGL_SELESAI','KET_SELESAI');
		
		$this->flexigrid->validate_post('TGL_ENTRY','desc',$valid_fields);

		$records = $this->helpdesk_model->get_helpdesk_grid();
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 1;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{
			$user_entry = '';
			$user_kerja = '';

			if (isset($row->USER_ENTRY) && $row->USER_ENTRY != '0') {
				foreach ($this->helpdesk_model->get_nama_entry($row->USER_ENTRY) as $key1) {
				$user_entry = $key1->NAMA_PEKERJA;
				}
			} else {
				$user_entry;
			}

			if (isset($row->USER_KERJA) && $row->USER_KERJA != '0') {
				foreach ($this->helpdesk_model->get_nama_kerja($row->USER_KERJA) as $key2) {
				$user_kerja = $key2->NAMA;
				}
			} else {
				$user_kerja;
			}	
			

			$record_items[] = array($row->KODE,
			$no,
			'<a href=\''.site_url().'/helpdesk/daftar/edit_helpdesk/'.$row->KODE.'/\'><img border=\'0\' src=\''.base_url().'images/main/28.png\'></a> ',
			'<a href=\''.site_url().'/helpdesk/daftar/tampil/'.$row->KODE.'/\' onclick="OpenPopup(this.href); return false"><img border=\'0\' src=\''.base_url().'images/main/77.png\'></a> ',			
			$row->KODE,
			$row->JENIS,
			$row->SUB_JENIS,
			$row->ISI,
			$row->TGL_ENTRY,
			$user_entry,
			$row->URAIAN,
			$user_kerja,
			$row->TGL_SELESAI,
			$row->KET_SELESAI
			);
			$no++;
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}

	function personal($username)
	{
		//ver lib
		
		/*
		 * 0 - display name
		 * 1 - width
		 * 2 - sortable
		 * 3 - align
		 * 4 - searchable (2 -> yes and default, 1 -> yes, 0 -> no.)
		 */
		$colModel['no'] = array('NO',40,TRUE,'center',0);
		$colModel['detail'] = array('DETAIL',50,FALSE,'center',0);
		$colModel['KODE'] = array('KODE',60,TRUE,'center',2);
		$colModel['JENIS'] = array('JENIS',80,TRUE,'center',2);
		$colModel['SUB_JENIS'] = array('SUB JENIS',80,TRUE,'center',2);
		$colModel['ISI'] = array('ISI',180,TRUE,'center',1);
		$colModel['TGL_ENTRY'] = array('TGL ENTRY',60, TRUE,'center',2);
		$colModel['USER_ENTRY'] = array('USER ENTRY',60, TRUE,'center',2);
		$colModel['URAIAN'] = array('URAIAN',60, TRUE,'center',2);
		$colModel['USER_KERJA'] = array('USER KERJA',60, TRUE,'center',2);
		$colModel['TGL_SELESAI'] = array('TGL SELESAI',90, TRUE, 'center',2);
		$colModel['KET_SELESAI'] = array('KET SELESAI',90, TRUE, 'center',2);
		
		
		/*
		 * Aditional Parameters
		 */
		$gridParams = array(
		'width' => 'auto',
		'height' => '355',
		'rp' => 15,
		'rpOptions' => '[10,15,20,25,40]',
		'pagestat' => 'Menampilkan: {from} sampai {to} dari {total} data.',
		'blockOpacity' => 0.5,
		'title' => 'Daftar Keseluruhan Permasalahan'
		);
		
		/*
		 * 0 - display name
		 * 1 - bclass
		 * 2 - onpress
		 */
		if ($this->session->userdata('jenis') == 'A'){
		$buttons[] = array('Complete Job','complete','helpdesk_js');
		$buttons[] = array('separator');
		$buttons[] = array('Pilih Semua','add','helpdesk_js');
		$buttons[] = array('Batal Memilih Semua','delete','helpdesk_js');
		//$buttons[] = array('separator');
        //$buttons[] = array('Cetak Data','print','helpdesk_js');
        //$buttons[] = array('separator');
    	}

		
		//Build js
		//View helpers/flexigrid_helper.php for more information about the params on this function
		$grid_js = build_grid_js('flex1',site_url("helpdesk/daftar/personal_grid/".$username),$colModel,'no','asc',$gridParams,$buttons);
		
		$data['title'] = "Contoh Flexigrid";
		$data['info'] = "Flexigrid";
		$data['js_grid'] = $grid_js;
		$data['version'] = "0.36";
		$data['download_file'] = "Flexigrid_CI_v0.36.rar";
		
		$data['added_js'] = 
			"<script type='text/javascript'>
			function helpdesk_js(com,grid)
			{
				if (com=='Pilih Semua')
				{
					$('.bDiv tbody tr',grid).addClass('trSelected');
				}
				
				if (com=='Batal Memilih Semua')
				{
					$('.bDiv tbody tr',grid).removeClass('trSelected');
				}

				if (com=='Cetak Data')
                {
                    location.href='".base_url()."index.php/helpdesk/daftar/cetak/'; 
                }
				
				if (com=='Tambah Helpdesk')
				{
					location.href='".base_url()."index.php/helpdesk/daftar/input_helpdesk'; 
				}

				if (com=='Assign Job')
				{
					if($('.trSelected',grid).length>0){
					   	var items = $('.trSelected',grid);
						var itemlist ='';
						for(i=0;i<items.length;i++){
							itemlist+= items[i].id.substr(3)+',';
						}						

							$.ajax({
							   	type: 'POST',
							   	url: '".site_url('/helpdesk/daftar/assign_job/')."',
							   	data: 'items='+itemlist,
							   	success: function(data){
							   	newwindow=window.open('".site_url('/helpdesk/daftar/assign_job/')."',
							   	'Pilih User Kerja','height=150,width=350');
								newwindow.document.write(data);
							    if (window.focus) {newwindow.focus()}
							    return false;
								$('#flex1').flexReload();
								alert(data);
							   }
							});
					} else {
						return false;
					}				   	
				}
				
				if (com=='Complete Job')
				{
				   if($('.trSelected',grid).length>0){
					   if(confirm('Anda yakin telah menyelesaikan Job ini ?')){
							var items = $('.trSelected',grid);
							var itemlist ='';
							for(i=0;i<items.length;i++){
								itemlist+= items[i].id.substr(3)+',';
							}
							$.ajax({
							   type: 'POST',
							   url: '".site_url('/helpdesk/daftar/complete_job')."',
							   data: 'items='+itemlist,
							   success: function(data){
								$('#flex1').flexReload();
								alert(data);
							   }
							});
						}
					} else {
						return false;
					} 
				}          
			} 
			</script>
			";
		
		/* $data['notification'] = "";
		if($this->session->userdata('notification')!=''){
			$data['notification'] = "
				<script>
					$(document).ready(function() {
						$.growlUI('Pesan :', '".$this->session->userdata('notification')."'); 
					});
				</script>
			";
		}//end if */	
		
		$data['content'] = $this->load->view('grid',$data,true);
		$this->load->view('main',$data);
		//$this->load->view('grid',$data);
		//$this->load->view('flexigrid',$data);
	}
	
	function personal_grid($username)
	{
	
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('KODE','JENIS','SUB_JENIS','ISI','TGL_ENTRY',
			'URAIAN','TGL_SELESAI','KET_SELESAI');
		
		$this->flexigrid->validate_post('TGL_ENTRY','desc',$valid_fields);

		$records = $this->helpdesk_model->get_helpdesk_personal_grid($username);
		
		$this->output->set_header($this->config->item('json_header'));
		$no = 1;
		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		foreach ($records['records']->result() as $row)
		{
			$user_entry = '';
			$user_kerja = '';

			if (isset($row->USER_ENTRY) && $row->USER_ENTRY != '0') {
				foreach ($this->helpdesk_model->get_nama_entry($row->USER_ENTRY) as $key1) {
				$user_entry = $key1->NAMA_PEKERJA;
				}
			} else {
				$user_entry;
			}

			if (isset($row->USER_KERJA) && $row->USER_KERJA != '0') {
				foreach ($this->helpdesk_model->get_nama_kerja($row->USER_KERJA) as $key2) {
				$user_kerja = $key2->NAMA;
				}
			} else {
				$user_kerja;
			}		
			

			$record_items[] = array($row->KODE,
			$no,
			//'<a href=\''.site_url().'/helpdesk/daftar/edit_helpdesk/'.$row->KODE.'/\'><img border=\'0\' src=\''.base_url().'images/main/28.png\'></a> ',
			'<a href=\''.site_url().'/helpdesk/daftar/tampil/'.$row->KODE.'/\' onclick="OpenPopup(this.href); return false"><img border=\'0\' src=\''.base_url().'images/main/77.png\'></a> ',			
			$row->KODE,
			$row->JENIS,
			$row->SUB_JENIS,
			$row->ISI,
			$row->TGL_ENTRY,
			$user_entry,
			$row->URAIAN,
			$user_kerja,
			$row->TGL_SELESAI,
			$row->KET_SELESAI
			);
			$no++;
		}
		//Print please
		if(isset($record_items))
				$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
			else
				$this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}

	
	function cek_validasi() {	
			// Setting Rules
			$this->form_validation->set_rules('jenis', 'Jenis', 'callback_cek_dropdown_jns');
			$this->form_validation->set_rules('sub_jenis', 'Sub Jenis', 'callback_cek_dropdown_sj');
			$this->form_validation->set_rules('isi', 'Isi', 'required');

			
			// Setting Error Message
			$this->form_validation->set_message('required', 'Kolom %s harus diisi!');
			$this->form_validation->set_message('numeric', 'Kolom %s hanya bisa diisi dengan menggunakan angka!');
			
			// Setting Delimiter
			$this->form_validation->set_error_delimiters('<li class="error">', '</li>');
			return $this->form_validation->run();	
	}
	
	function input_helpdesk()
    {
		$jenis = $this->kategori_model->get_kategori();
				
 		if ($this->cek_validasi() == FALSE){
				
				$jenis_options['1'] = '-- Pilih Jenis Permasalahan --';
						foreach($jenis->result() as $jns)
						{
						$jenis_options[$jns->ID_REF_DATA] = $jns->ID_REF_DATA;
						}
				
				$sub_jenis_options['0'] = '-- Pilih Sub Jenis Permasalahan --';
				if(isset($_POST['jenis'])){
				$sub = $this->kategori_model->get_sub_by_jenis($this->input->post('jenis'));
					foreach($sub->result() as $sj){
						$sub_jenis_options[$sj->KET_REF_DATA] = $sj->KET_REF_DATA;
					}
				}
				
				$data['jenis_options'] = $jenis_options;
				$data['sub_jenis_options'] = $sub_jenis_options;
				$data['status'] = 'new';
				$data['content'] = $this->load->view('helpdesk/form_helpdesk',$data,true);
				$this->load->view('main',$data);
			}
			else{
				$this->insert_helpdesk();
			}            
    }
	
	function insert_helpdesk(){
		$today = date('d-M-Y');
		$counter = $this->helpdesk_model->count_all_helpdesk();
		$nomor = sprintf("%06d", ($counter + 1));
		$kode = 'HD'.$nomor;
				
		$data = array
		(
			'KODE' 					=> $kode,
			'JENIS' 				=> $this->input->post('jenis'),
			'SUB_JENIS' 			=> $this->input->post('sub_jenis'),
			'ISI' 					=> $this->input->post('isi'),
			'URAIAN' 				=> $this->input->post('uraian'),
			'KETERANGAN' 			=> $this->input->post('keterangan'),
			'TGL_ENTRY' 			=> $today,
			'USER_ENTRY' 			=> $this->session->userdata('username'),
			'PROGRAM_NAME' 			=> "WEB"
		);
		
		$this->helpdesk_model->add_helpdesk($data);
		redirect('helpdesk/daftar/all'); 
	}
	
	function edit_helpdesk($id_helpdesk)
    {
		$this->session->set_userdata('id_helpdesk',$id_helpdesk);
		$jenis = $this->kategori_model->get_kategori();

		$jenis_options['1'] = '-- Pilih Jenis Permasalahan --';
			foreach($jenis->result() as $jns)
				{
					$jenis_options[$jns->ID_REF_DATA] = $jns->ID_REF_DATA;
				}
				
		$sub_jenis_options['0'] = '-- Pilih Sub Jenis Permasalahan --';
			if(isset($_POST['jenis'])){
				$sub = $this->kategori_model->get_sub_by_jenis($this->input->post('jenis'));
				foreach($sub->result() as $sj){
						$sub_jenis_options[$sj->KET_REF_DATA] = $sj->KET_REF_DATA;
					}
				}

		$helpdesk = $this->helpdesk_model->get_id_helpdesk($id_helpdesk);
		
 		if ($this->cek_validasi() == FALSE){
				$data['helpdesk'] = $helpdesk;
				$data['jenis_options'] = $jenis_options;
				$data['sub_jenis_options'] = $sub_jenis_options;
	 			$data['status'] = 'edit'; 			
				$data['content'] = $this->load->view('helpdesk/form_helpdesk',$data,TRUE);
				$this->load->view('main',$data);
				
			}
			else{
				$this->update_helpdesk($id_helpdesk);
			}            
    }
	
	function update_helpdesk($id_helpdesk){
		$data = array(
			'JENIS' 				=> $this->input->post('jenis'),
			'SUB_JENIS' 			=> $this->input->post('sub_jenis'),
			'ISI' 					=> $this->input->post('isi'),
			'URAIAN' 				=> $this->input->post('uraian'),
			'KETERANGAN' 			=> $this->input->post('keterangan')	
		);

		$this->helpdesk_model->edit_helpdesk($id_helpdesk,$data);
		redirect('helpdesk/daftar/all');
	}

	function assign_job()
	{
		$kerja = $this->helpdesk_model->get_all_nama_kerja();
			$kerja_options[''] = '-- Pilih Karyawan Yang Akan Mengerjakan --';
				foreach($kerja as $krj)
					{
						$kerja_options[$krj->KODE] = $krj->NAMA;
					}

			$data['kerja_options'] = $kerja_options;

		if ($this->input->post('user_kerja') != '') {
			$helpdesk_id_array = explode(",",$this->input->post('helpdesk_id'));
			foreach($helpdesk_id_array as $index => $id_helpdesk){
				if (isset($id_helpdesk) && $id_helpdesk != "") {
					$edit = array(
						'USER_KERJA' 			=> $this->input->post('user_kerja')
					);
					$this->helpdesk_model->edit_helpdesk($id_helpdesk,$edit);
				}
			}

			$data['script'] = "<script>window.close(); $('#flex1').flexReload();</script>";
			$this->load->view('helpdesk/assign_helpdesk',$data);
		} 
		else 
		{
			
			$data['script'] = '';
			$data['helpdesk_ids_post_array'] = explode(",",$this->input->post('items'));
			$this->load->view('helpdesk/assign_helpdesk',$data);
		}		
	}
	
	function complete_job()
	{
		$today = date('d-M-Y');
		$helpdesk_ids_post_array = explode(",",$this->input->post('items'));
		$msg = '';
		foreach($helpdesk_ids_post_array as $index => $id_helpdesk){
			if (isset($id_helpdesk) && $id_helpdesk != "") {
				$data = array(
					'TGL_SELESAI' 			=> $today,
					'KET_SELESAI' 			=> 'OK'	
				);
				$this->helpdesk_model->edit_helpdesk($id_helpdesk,$data);
						
			
			$msg .= "Helpdesk dengan id (".$id_helpdesk.") telah diselesaikan.\n";
			}
		}
		$this->output->set_header($this->config->item('ajax_header'));
		$this->output->set_output($msg);
	}
	//Delete
	function delete_helpdesk()
	{
		$helpdesk_ids_post_array = explode(",",$this->input->post('items'));
		$msg = '';
		foreach($helpdesk_ids_post_array as $index => $id_helpdesk){
			if (isset($id_helpdesk) && $id_helpdesk != "") {
				$this->helpdesk_model->delete_helpdesk($id_helpdesk);
						
			
			$msg .= "Helpdesk dengan id (".$id_helpdesk.") telah berhasil dihapus.\n";
			}
		}
		$this->output->set_header($this->config->item('ajax_header'));
		$this->output->set_output($msg);
	}
    
    //Print
    function cetak()
    {
        $data['helpdesk'] = $this->helpdesk_model->get_helpdesk();
        $header = '';
		header("Content-type: application/x-msdownload"); 
		header("Content-Disposition: attachment; filename=Rekap_helpdesk.xls"); 
		header("Pragma: no-cache"); 
		header("Expires: 0");
		echo $header;
				
		$this->load->view('rekap/cetak_helpdesk_all',$data);
    }

	function tampil($id_helpdesk)
	{
		$record_helpdesk = $this->helpdesk_model->get_id_helpdesk($id_helpdesk);
			foreach ($record_helpdesk->result() as $row){
				if (isset($row->USER_ENTRY)) {
					foreach ($this->helpdesk_model->get_nama_entry($row->USER_ENTRY) as $key1) {
					$user_entry = $key1->NAMA_PEKERJA;
					}
				} else {
					$user_entry ='';
				}

				if (isset($row->USER_KERJA)) {
					foreach ($this->helpdesk_model->get_nama_kerja($row->USER_KERJA) as $key2) {
					$user_kerja = $key2->NAMA;
					}
				} else {
					$user_kerja = '';
				}
                $data['kode'] = $row->KODE;
                $data['jenis'] = $row->JENIS;
                $data['sub_jenis'] = $row->SUB_JENIS;
                $data['isi'] = $row->ISI;
                $data['keterangan'] = $row->KETERANGAN;
                $data['tgl_entry'] = $row->TGL_ENTRY;
                $data['user_entry'] = $user_entry;
                $data['uraian'] = $row->URAIAN;
                $data['user_kerja'] = $user_kerja;
                $data['tgl_selesai'] = $row->TGL_SELESAI;
                $data['ket_selesai'] = $row->KET_SELESAI;
            }
		
		$this->load->view('helpdesk/detail_helpdesk',$data);
	}
	
	//cek_dropdown
	function cek_kode($value){
	$kode= $this->input->post('kode');
	$cek_kode= $this->helpdesk_model->get_id_helpdesk($kode);
	$c_kode='';
	foreach ($cek_kode->result() as $rows){
			$c_kode=$rows->KODE;
		}
		if($c_kode != ''){
			return TRUE;
		}
		elseif($c_kode == $kode){
			$this->$this->form_validation->set_message('cek_kode', 'Kode sudah ada');
		}
		else{
			$this->form_validation->set_message('cek_kode', 'Kolom %s harus diisi!!');
			return FALSE;
		}
	}

	function cek_dropdown_jns($value){
	$jenis= $this->input->post('jenis');
		if($jenis == 1 || $jenis == '1' || $jenis ==''){
			$this->form_validation->set_message('cek_dropdown_jns', 'Kolom %s harus diisi!!');
			return FALSE;
		}
		else{
			return TRUE;
		}
	}
	
	function cek_dropdown_sj($value){
	$sub_jenis= $this->input->post('sub_jenis');
	$cek_sj= $this->kategori_model->get_sub_by_name($sub_jenis);
	$c_sj='';
	foreach ($cek_sj->result() as $rows){
			$c_sj=$rows->KET_REF_DATA;
		}
		if($c_sj != ''){
			return TRUE;
		}
		else{
			$this->form_validation->set_message('cek_dropdown_sj', 'Kolom %s harus diisi!!');
			return FALSE;
		}
	}
}
?>